package be.jaisy.project.adapter.factory.impl;

import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;

import be.jaisy.project.adapter.IProjectDao;
import be.jaisy.project.adapter.factory.DaoFactory;
import be.jaisy.project.adapter.impl.ProjectDaoImpl;

public class HibernateDaoFactoryImpl extends DaoFactory {

	private static String SESSION_FACTORY_ID = "JaisyDB";
	
    /**
     * @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration)
     */
    public Object getService(Bundle bundle, ServiceRegistration reg) {  
    	   	
    	ServiceReference projectDaoServiceReference = bundle.getBundleContext().getServiceReference(IProjectDao.class.getName());
    	if(reg.getReference().equals(projectDaoServiceReference)){
	        return getProjectDao();
    	} 
    	    	
    	return null;
     }
     /**
     * @see org.osgi.framework.ServiceFactory#ungetService(org.osgi.framework.Bundle, org.osgi.framework.ServiceRegistration, java.lang.Object)
     */
    public void ungetService(Bundle bundle, ServiceRegistration reg, Object service) {
    	 //nothing to do
     }
    
	/**
	 * @see be.jaisy.project.adapter.factory.DaoFactory#getProjectDao()
	 */
	@Override
	public IProjectDao getProjectDao() {
		IProjectDao projectDao = new ProjectDaoImpl(SESSION_FACTORY_ID);
    	return projectDao;
	}
	
	

}
